﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace IOCWindows.controls
{
    public class IocWindow :Window
    {
        public IocWindow()
        {
            var type = this.GetType();
            //获取私有成员，并带有InjectAttribute 的成员
            var fields = type.GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
                .Where(f => f.GetCustomAttributes(typeof(Ninject.InjectAttribute), false).Count() > 0);

            //在ninject中查找有没有相关的注入项
            foreach (var field in fields)
            {
                var instance = NinjectIOCfact.Get(field.FieldType);
                if (instance != null)
                    field.SetValue(this, instance);

            }

        }

    }
}
